<template>
  <!-- 供应商 -->
  <div class="app-container">
    <!-- 搜索查询 -->
    <div class="form-container">
      <el-form ref="queryForm" :inline="true" label-width="80px" :model="filters">
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="filters.enterpriseName" clearable placeholder="请输入企业名称" size="small" />
        </el-form-item>
        <el-form-item label="企业类型" prop="typeNum">
          <el-select v-model="filters.typeNum" placeholder="请选择企业类型" clearable size="small">
            <el-option
              v-for="dict in enterTypeOptions"
              :key="dict.typeNum"
              :label="dict.typeName"
              :value="dict.typeNum"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="dateRange"
            size="small"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :clearable="false"
          />
        </el-form-item>
      </el-form>
    </div>
    <!--操作按钮-->
    <div class="btns-group">
      <el-button v-clickForbidden icon="el-icon-search" size="middle" @click="handleQuery">搜索</el-button>
      <el-button v-clickForbidden icon="el-icon-refresh" size="middle" @click="resetQuery">重置</el-button>
      <el-button icon="el-icon-zoom-in" size="middle" :disabled="single" @click="handleDetail">详情</el-button>
      <!--      <el-button v-hasPermi="['system:user:operatorUserList']" icon="el-icon-aim" size="middle" :disabled="single" @click="handlePerson">企业人员</el-button>-->
      <!--      <el-button v-hasPermi="['system:sysEquipment:equipmentList']" icon="el-icon-aim" size="middle" :disabled="single" @click="handleEquipment">企业设备</el-button>-->
      <el-button v-hasPermi="['system:proEnterprise:teamProjectList']" icon="el-icon-tickets" size="middle" :disabled="single" @click="handleProject">参与项目</el-button>
    </div>
    <!-- 表格展示start -->
    <sk-table
      :loading="loading"
      :multiple-selection.sync="multipleSelection"
      :table-data.sync="tableData"
      :single.sync="single"
      :page-size="filters.pageSize"
    >
      <template #column>
        <el-table-column type="selection" width="38" />
        <el-table-column label="序号" type="index" width="55" align="center" />
        <el-table-column prop="name" :show-overflow-tooltip="true" label="企业名称" min-width="150" align="center" />
        <el-table-column prop="sysEnterpriseType" :formatter="formartType" label="企业类型" min-width="80" align="center" />
        <el-table-column prop="creditCodePic" label="信用代码" :show-overflow-tooltip="true" min-width="150" align="center" />
        <el-table-column prop="contacts" label="联系人" min-width="80" align="center" />
        <el-table-column prop="phone" label="联系电话" min-width="60" align="center" />
      </template>
    </sk-table>
    <!-- 表格展示end-->

    <!-- 分页器 -->
    <pagination
      class="pagination-container"
      :total="total"
      :page.sync="filters.pageNum"
      :limit.sync="filters.pageSize"
      @pagination="getList"
    />
    <!-- 企业信息新增修改组件start -->
    <addDialog ref="addDialog" :type-options="enterTypeOptions" />
    <!-- 企业信息新增修改组件end -->

    <!-- 企业信息详情组件start -->
    <detailDialog ref="detailDialog" />
    <!-- 企业信息详情组件end -->
  </div>
</template>

<script>
import { listNoPermission } from '@/api/superviseBaseInfo/typeManage/organizationType'
// 勘察单位
import { listCooperativeEnterprise } from '@/api/supplier/cooperativeEnterprise'
import addDialog from './components/addDialog'
import detailDialog from './components/detailDialog'
export default {
  name: 'CooperativeEnterprise',
  components: {
    addDialog,
    detailDialog
  },
  data() {
    return {
      // 筛选条件
      filters: {
        pageNum: 1,
        pageSize: this.fristPageSize,
        enterpriseName: '', // 企业名称
        typeNum: '' // 企业类型
      },
      // 日期范围
      dateRange: [],
      enterTypeOptions: [], // 企业类型数组
      /* 列表 start*/
      total: 0, // 分页总条数
      single: true, // 非单个禁用
      multipleSelection: [], // 选中表格行
      loading: false, // 列表加载
      tableData: []
      /* 列表 end*/
    }
  },
  created() {
    // 获取列表数据
    this.getList()
    this.getSupperType()
  },
  mounted() {
    if (this.$route.query.id) this.$refs.detailDialog.handleAdd('企业详情', this.$route.query.id)
  },
  methods: {
    // 获取列表数据
    async getList() {
      try {
        this.loading = true
        const { data: { rows, total }} = await listCooperativeEnterprise(this.changeDateRange(this.filters, this.dateRange))
        this.tableData = rows
        this.total = total
        this.loading = false
      } catch {
        this.loading = false
      }
    },
    // 获取单位类型
    async getSupperType() {
      const { data: { rows }} = await listNoPermission()
      this.enterTypeOptions = [{ typeNum: '', typeName: '全部' }, ...rows]
    },
    // 回显单位类型
    formartType(row) {
      if (JSON.stringify(row) === '{}') return
      const item = this.enterTypeOptions.find(item => {
        return item.typeNum === row.sysEnterpriseType
      })
      return item && item.typeName
    },
    /* 按钮 Start */
    // 搜索方法
    handleQuery() {
      this.filters.pageNum = 1
      this.getList()
    },
    // 重置搜索
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 新增
    handleAdd() {
      this.$refs.addDialog.handleAdd('添加企业')
    },
    // 详情
    handleDetail() {
      this.$refs.detailDialog.handleAdd('企业详情', this.multipleSelection[0].id)
    },
    // 查看人员
    handlePerson() {
      const { id } = this.multipleSelection[0]
      this.$router.push({
        path: '/resourceManage/supplierPerson',
        query: { id }
      })
    },
    // 查看设备
    handleEquipment() {
      const { id } = this.multipleSelection[0]
      this.$router.push({
        path: '/resourceManage/supplierEquipment',
        query: { id }
      })
    },
    // 参与项目
    handleProject() {
      const { id } = this.multipleSelection[0]
      this.$router.push({
        path: '/resourceManage/JoinProject',
        query: { id }
      })
    }
    /* 按钮 end */
  }
}
</script>

